//-----------------------------------------------------------------------------
// Bend2D - Physics Engine
// Roberto Bender <beto.bender@gmail.com>
// Description: 
// Date: 09/03/2010
//-----------------------------------------------------------------------------
#include "angle.h"
#include "bmath.h"
using namespace bend2d;

Angle::Angle() :
    m_Angle(0)
{
}

Angle::Angle(double angle, AngleRepresentation input)
{
    switch(input)
    {
        case eAngleDegree:
            m_Angle = angle;
            break;
        case eAngleRad:
            m_Angle = (angle * 180.0) / Math::pi;
            break;
    }
}

double Angle::GetAngle(AngleRepresentation output) const
{
    switch(output)
    {
        case eAngleDegree:
            return m_Angle;
        case eAngleRad:
            return (m_Angle * Math::pi) / 180.0;
        case eAngleDegreePos:
            {
                double angle = m_Angle;
                while(angle < 0) angle += 360.0;
                while(angle > 360) angle -= 360.0;
                return angle;
            }
    }
    return 0;
}

Angle Angle::operator + (const Angle& angle) const
{
    Angle rangle(*this);
    rangle+=angle;
    return rangle;
}

Angle Angle::operator - (const Angle& angle) const
{
    Angle rangle(*this);
    rangle-=angle;
    return rangle;
}

void Angle::operator += (const Angle& angle)
{
    this->m_Angle += angle.m_Angle;
}

void Angle::operator -= (const Angle& angle)
{
    this->m_Angle -= angle.m_Angle;
}

void Angle::Rotate(const Angle& angle, AngleOrigin origin)
{
    switch(origin)
    {
        case eAngleAbsolute:
            m_Angle = angle.m_Angle;
            break;
        case eAngleRelative:
            m_Angle += angle.m_Angle;
            break;
    }
}

Angle Angle::Rotate(const Angle& angle, AngleOrigin origin) const
{
	Angle rangle(*this);
	rangle.Rotate(angle, origin);
	return rangle;
}
